define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pay/merchant/index' + location.search,
                    add_url: 'pay/merchant/add',
                    edit_url: 'pay/merchant/edit',
                    del_url: 'pay/merchant/del',
                    multi_url: 'pay/merchant/multi',
                    import_url: 'pay/merchant/import',
                    table: 'pay_merchant',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},

                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.toggle,yes:"1",no:"2"},

                        {field: 'province', title: __('Province'), operate: 'LIKE'},
                        {field: 'city', title: __('City'), operate: 'LIKE'},
                        {field: 'wechat', title: __('Wechat'), searchList: {"1":__('Wechat 1'),"2":__('Wechat 2')}, formatter: Table.api.formatter.normal},
                        {field: 'store', title: __('Store'), operate: 'LIKE'},
                        {field: 'code', title: __('Code'), operate: 'LIKE'},
                        {field: 'business_account', title: __('Business_account'), operate: 'LIKE'},
                        {field: 'business_password', title: __('Business_password'), operate: 'LIKE'},
                        {field: 'refund_password', title: __('Refund_password'), operate: 'LIKE'},
                        {field: 'wechat_account', title: __('Wechat_account'), operate: 'LIKE'},
                        {field: 'wechat_code', title: __('Wechat_code'), operate: 'LIKE'},
                        {field: 'async_key', title: __('Async_key'), operate: 'LIKE'},
                        {field: 'no_password', title: __('No_password'), searchList: {"1":__('No_password 1'),"2":__('No_password 2')}, formatter: Table.api.formatter.normal},
                        {field: 'quota', title: __('Quota'), operate: 'LIKE'},
                        {field: 'today_quota', title: __('Today_quota'), operate: 'LIKE'},
                        {field: 'quota_time', title: __('Quota_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            $(".btn-update-cache").on("click",function(e){
                e.preventDefault();
                Fast.api.ajax({
                    url: 'pay/merchant/updateCache'
                    // data: form.serialize()
                }, function (data) {
                    Fast.api.close();
                    parent.Toastr.success('操作成功');
                    // parent.$(".btn-refresh").trigger("click");
                });
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
